<?php
if(!defined('SE_PAGE')) exit;

function MSEP_Top($plugin)
{
      global $database, $url;

      $msep_s = $database->database_fetch_assoc($database->database_query("SELECT plugin_disabled, plugin_order FROM se_plugins WHERE plugin_type='msep' LIMIT 1"));
      $msep_t = $database->database_fetch_assoc($database->database_query("SELECT plugin_order FROM se_plugins WHERE plugin_type='{$plugin}' LIMIT 1"));
      $msep_a = $database->database_fetch_assoc($database->database_query("SHOW TABLE STATUS LIKE 'se_plugins'"));

      $refresh_url = urldecode($url->url_current());

      if (!empty($msep_s['plugin_disabled']) || $msep_s['plugin_disabled'] == 1)
      {
            $database->database_query("UPDATE se_plugins SET plugin_disabled='1' WHERE plugin_type='{$plugin}'");

            header("Location: {$refresh_url}");
            exit;
      }
      elseif ($msep_t['plugin_order'] < $msep_s['plugin_order'])
      {
            $database->database_query("UPDATE se_plugins SET plugin_order='{$msep_s['plugin_order']}' WHERE plugin_type='{$plugin}'");
            $database->database_query("UPDATE se_plugins SET plugin_order='{$msep_t['plugin_order']}' WHERE plugin_type='msep'");

            header("Location: {$refresh_url}");
            exit;
      }
      elseif ($msep_t['plugin_order'] == $msep_s['plugin_order'])
      {
            $database->database_query("UPDATE se_plugins SET plugin_order='{$msep_a['Auto_increment']}' WHERE plugin_type='{$plugin}'");

            header("Location: {$refresh_url}");
            exit;
      }
}
?>